package cc.ifok.kit;

import java.nio.charset.StandardCharsets;
import java.util.Optional;

public final class Strings {
    public static final String EMPTY = "";
    private Strings() {}

    public static String trim(String val) {
        return Optional.ofNullable(val).orElse(EMPTY).trim();
    }

    public static byte[] bytes(String val) {
        return trim(val).getBytes(StandardCharsets.UTF_8);
    }

    public static String string(byte[] val) {
        return new String(Optional.ofNullable(val).orElse(new byte[0]), StandardCharsets.UTF_8);
    }
}
